package com.yzkj.cpjxc.business.framework.common;

import java.io.Serializable;
import java.util.*;

/**
 * 分页对象
 */
public class Pager<T> implements Serializable {

	private static final long serialVersionUID = -674342573401174523L;

	public final static String CURRENT_PAGE = "currentPage";

	private int limit = 10;

	private boolean hasPre;

	private boolean hasNext;

	private int currentPage = 1;

	private Long total;

	private boolean needPage = true;

	private List<T> dataList = new ArrayList<T>();
	
	private List<Integer> limitList = new ArrayList<Integer>();

	private String ids;

	private Date beginDate;

	private Date endDate;

	private String submitFlag;
	
	private String dicGroupType;
	
	private String beginDateStr;
	
	private String endDateStr;
	
	private Map<String, Object> param = new HashMap<String, Object>();

	/**容器ID,主要用来load进分页页面的：*/
	private String containerId;

	/**上一页,下一页等调用的url： */
	private String url;

	/**
	 * myPagination分页组件传过来的当前页数(第几页)
	 */
	public final static String MY_PAGINATION_CURRENT_PAGE = "page";

	public Pager() {

	}

	public Pager(boolean needPage) {
		this.needPage = needPage;
	}

	public Pager(int currentPage, Long total) {
		super();
		this.currentPage = currentPage;
		this.total = total;
	}

	public Pager(int limit, int currentPage, Long total) {
		super();
		this.limit = limit;
		this.currentPage = currentPage;
		this.total = total;
	}

	public int getTotalPage() {
		try {
			if (0 == total) {
				return 1;
			}
		} catch (Exception e) {
			return 1;
		}
		return (int) (total - 1) / this.getLimit() + 1;
	}

	public boolean isFirstPage() {
		return 1 == currentPage ? true : false;
	}

	public boolean isLastPage() {
		return currentPage == getTotalPage() ? true : false;
	}

	/** 获取上一页是第几页 */
	public int getPrePage() {
		return currentPage - 1;
	}

	/** 获取下一页是第几页 */
	public int getNextPage() {
		return currentPage + 1;
	}

	// /////////////////////////////////////////////////////////////////////////

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public boolean isHasPre() {
		return hasPre;
	}

	public void setHasPre(boolean hasPre) {
		this.hasPre = hasPre;
	}

	public boolean isHasNext() {
		return hasNext;
	}

	public void setHasNext(boolean hasNext) {
		this.hasNext = hasNext;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public Long getTotal() {
		return total;
	}

	public void setTotal(Long total) {
		this.total = total;
	}

	public boolean isNeedPage() {
		return needPage;
	}

	public void setNeedPage(boolean needPage) {
		this.needPage = needPage;
	}

	public List<T> getDataList() {
		return dataList;
	}

	public void setDataList(List<T> dataList) {
		this.dataList = dataList;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public String getSubmitFlag() {
		return submitFlag;
	}

	public void setSubmitFlag(String submitFlag) {
		this.submitFlag = submitFlag;
	}

	public Map<String, Object> getParam() {
		return param;
	}

	public void setParam(Map<String, Object> param) {
		this.param = param;
	}

	public String getContainerId() {
		return containerId;
	}

	public void setContainerId(String containerId) {
		this.containerId = containerId;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public List<Integer> getLimitList() {
		limitList.add(5);
		limitList.add(10);
		limitList.add(12);
		limitList.add(15);
		limitList.add(20);
		limitList.add(50);
		limitList.add(100);
		limitList.add(1000);
		return limitList;
	}

	public void setLimitList(List<Integer> limitList) {
		this.limitList = limitList;
	}

	public String getDicGroupType() {
		return dicGroupType;
	}

	public void setDicGroupType(String dicGroupType) {
		this.dicGroupType = dicGroupType;
	}
	
	public String getBeginDateStr() {
		return beginDateStr;
	}

	public void setBeginDateStr(String beginDateStr) {
		this.beginDateStr = beginDateStr;
	}

	public String getEndDateStr() {
		return endDateStr;
	}

	public void setEndDateStr(String endDateStr) {
		this.endDateStr = endDateStr;
	}

}
